/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.tom.social.analyzer.common;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.table.TableModel;
import pl.tom.social.analyzer.gui.component.TableResultTopComponent;
import pl.tom.social.common.types.AnalysisType;

/**
 *
 * @author Tom
 */
public class Results {
	public static void show(TableModel model, AnalysisType type) {
		TableResultTopComponent results = new TableResultTopComponent(model, type);
		results.open();
		results.requestActive();
	}

	public static Map<String, Double> normalize(Map<String, Integer> termCount, int top) {
		Map<String, Double> result = new HashMap<String, Double>();

		Double max = 0d;
		for(Iterator<Integer> iter = termCount.values().iterator(); iter.hasNext();) {
			Integer current = iter.next();
			if(current > max) {
				max = (double)current;
			}
		}

		for(Iterator<String> iter = termCount.keySet().iterator(); iter.hasNext();) {
			String term = iter.next();
			result.put(term, 100 * termCount.get(term) / max);
		}
		return result;
	}
}
